const path = require('node:path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const SpeedMeasureWebpackPlugin = require('speed-measure-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerWebpackPlugin = require('css-minimizer-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')
const { PurgeCSSPlugin } = require('purgecss-webpack-plugin')
const glob = require('glob-all')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

/**
 * @type {import('webpack').Configuration}
 */
const prodConfig = {
  mode:'production',
  optimization:{
    splitChunks:{
      cacheGroups:{
        vendor:{
          test:/node_modules/,
          name:'vendor',
          minChunks: 1,
          chunks:'initial',
          minSize: 0,
          priority: 1
        },
        common:{}
      }
    },
    minimizer:[
      new CssMinimizerWebpackPlugin(),
      new TerserWebpackPlugin({
        parallel:true,
        terserOptions:{
          compress:{
            pure_funcs:['console.log']
          }
        }
      })
    ]
  },
  plugins:[
    new CopyWebpackPlugin({
      patterns:[
        {
          from:'',
          to:'',
          filter(source) {

          }
        }
      ]
    }),
    new BundleAnalyzerPlugin(),
    new MiniCssExtractPlugin({
      filename:''
    }),
    new PurgeCSSPlugin({
      paths:glob.sync([

      ]),
      safelist:[]
    }),
    new CompressionWebpackPlugin({
      test:/\.(js,css)$/,
      filename:'[path][base].gz',
      algorithm:'gzip',
      minRatio: 0.8,
      threshold: 10 * 1024
    })
  ]
}
